﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Collections;
using System.Windows.Media;
using System.Windows;
using CommomFunctions;

namespace Filas
{
    public class Images : CommomFunctions.Imagens
    {
        /// <summary>
        /// Contains the images that will be used to fill the elements of the queue
        /// </summary>
        ArrayList people = new ArrayList();
        
        public Images(int numElements)
        {
            createPeopleImages(numElements);
        }
        
        /// <summary>
        /// Loads the files containing the images of different emoticons and adds them to "people"
        /// </summary>
        /// <param name="numElements">
        /// Maximum number of elements in the queue
        /// </param>
        private void createPeopleImages(int numElements)
        {
            ArrayList imagens = new ArrayList();

            imagens.Add(Filas.Properties.Resources.person_Copy_1);
            imagens.Add(Filas.Properties.Resources.person_Copy_2);
            imagens.Add(Filas.Properties.Resources.person_Copy_3);
            imagens.Add(Filas.Properties.Resources.person_Copy_4);
            imagens.Add(Filas.Properties.Resources.person_Copy_5);
            imagens.Add(Filas.Properties.Resources.person_Copy_6);
            imagens.Add(Filas.Properties.Resources.person_Copy_7);
            imagens.Add(Filas.Properties.Resources.person_Copy_8);
            imagens.Add(Filas.Properties.Resources.person_Copy_9);
            imagens.Add(Filas.Properties.Resources.person_Copy_10);            
         
            for (int i = 0; i < numElements; i++)
            {
                ImageBrush berriesBrush = new ImageBrush();

                berriesBrush.ImageSource = loadBitmap((System.Drawing.Bitmap)imagens[i]);
                people.Add(berriesBrush);
            }
            
        }

        /// <summary>
        /// Creates and adds to grid all the images that will be used to indicates the queue emptyness (BeginNull, EndNull and Null)
        /// and the queue begin and end (Begin and End)
        /// </summary>
        /// <param name="gd"></param>
        internal void createControlImages(Grid gd)
        {
            loadSources();
            
            setAlignments(WorkingImage.Begin, Stretch.Uniform, VerticalAlignment.Bottom, HorizontalAlignment.Center);
            setCollumnsAndLines(WorkingImage.Begin, gd, 0, 1, 3, 1);

            setAlignments(WorkingImage.End, Stretch.Uniform, VerticalAlignment.Top, HorizontalAlignment.Center);
            setCollumnsAndLines(WorkingImage.End, gd, 0, 6, 1, 2);

            setAlignments(WorkingImage.BeginNull, Stretch.Uniform, VerticalAlignment.Top, HorizontalAlignment.Center);
            setCollumnsAndLines(WorkingImage.BeginNull, gd, 0, 9, 3, 2);

            setAlignments(WorkingImage.EndNull, Stretch.Fill, VerticalAlignment.Bottom, HorizontalAlignment.Center);
            setCollumnsAndLines(WorkingImage.EndNull, gd, 0, 9, 2, 1);

            setAlignments(WorkingImage.Null, Stretch.Fill, VerticalAlignment.Bottom, HorizontalAlignment.Center);
            setCollumnsAndLines(WorkingImage.Null, gd, 0, 9, 1, 2);

            setImagesVisibility(Visibility.Hidden);
            setNullImagesVisibility(Visibility.Hidden);
        }

        /// <summary>
        /// Sets the margins of the images "inicio" and "final"
        /// </summary>
        internal void gridSizeChanged()
        {
            inicio.Margin = new Thickness(65, 0, 0, 35);
            final.Margin = new Thickness((66 * (ControlVariables.contAdd)), 20, (66 * (10 - ControlVariables.contAdd + 1)), 32);
        }

        /// <summary>
        /// Returns the image at index "ind" that will be used to fill the specified element
        /// </summary>
        /// <param name="ind"></param>
        /// <returns></returns>
        internal ImageBrush getFillImage(int ind)
        {
            return ((ImageBrush)people[ind]);
        }
    }
}
